package com.lx.base.config.converter;


import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author lixing
 * @date 2022/6/29 13:38
 */
public class LocalTimeJacksonConverter extends JsonDeserializer<LocalTime> {


    @Override
    public LocalTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        LocalDateTimeJacksonConverter localDateTimeJacksonConverter=new LocalDateTimeJacksonConverter();
        LocalDateTime localDateTime=localDateTimeJacksonConverter.deserialize(p,ctxt);
        if(localDateTime==null){
            return null;
        }
        return localDateTime.toLocalTime();
    }

    @Override
    public Class<?> handledType() {
        return LocalTime.class;
    }

}
